package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.service.WorkBenchService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/workbench")
public class WorkBenchController {

    @Reference
    private WorkBenchService workBenchService;

    /*
    * (工作台)VUE对象初始化完成后,查询数据
    * */
    @GetMapping("/getMessage")
    public Result getMessage(){

        Map<String,Object> map= null;

        try {
            map = workBenchService.getMessage();

            //判断key是否存在,否则页面为空
            String[] arr={"todayOrderNumber","todayAssessmentNumber","todayNonExecution","todayExecuted",
                    "totalOrderNumber","totalAssessmentNumber","totalNonExecution","totalExecuted","questionnaire",
                    "scheme","trace","todayNewMember","todayLoginMember","totalMember"};
            for (String s : arr) {
                boolean b = map.containsKey(s);
                if (!b){
                    map.put(s,0);
                }
            }


        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "获取数据失败");
        }

        return new Result(true,"获取数据成功",map);
    }
}
